RM := rm -f
## Use compiler from configure. May be specified by user with e.g.:
## ./configure CXX=/usr/local/bin/g++-7
CXX := @CXX@

PREFIX := @prefix@
MANDIR = $(PREFIX)/share/man

CPPFLAGS := @CPPFLAGS@
LDFLAGS := @LDFLAGS@

# profiling:
#-g -pg

## set the nlopt around
HNLOPT := @HNLOPT@
HARM := @HARM@
HOMP := @HOMP@

CPP_LIBS = -llapack -lblas -lpthread -lm
ifeq "$(HNLOPT)" "Y"
    CPP_LIBS += -lnlopt
endif

ifeq "$(HARM)" "Y"
    CPP_LIBS += -larmadillo
endif

OPT_FLAGS := @OPT_FLAGS@ -Wall
ifeq "$(HOMP)" "Y"
    OPT_FLAGS += -DOMP
endif

ifneq "$(CXX)" "icc"
    OPT_FLAGS += -ffast-math -ftree-vectorize
endif

NLOPT_PROGRAMS :=
ifeq "$(HNLOPT)" "Y"
    NLOPT_PROGRAMS += pxbdfit
endif

FFLAGS	= -O3

CONSEQ_SRC = main_consq.cpp
CONSEQ_OBJ = main_consq.o
CONSEQ_DEP = main_consq.d

STREC_SRC = main_strec.cpp
STREC_OBJ = main_strec.o
STREC_DEP = main_strec.d

MRCA_SRC = main_mrca.cpp
MRCA_OBJ = main_mrca.o
MRCA_DEP = main_mrca.d

MRCACUT_SRC = main_mrca_cut.cpp
MRCACUT_OBJ = main_mrca_cut.o
MRCACUT_DEP = main_mrca_cut.d

MRCANAME_SRC = main_mrca_name.cpp
MRCANAME_OBJ = main_mrca_name.o
MRCANAME_DEP = main_mrca_name.d

BD_SIM_SRC = bd_sim.cpp main_bd_sim.cpp
BD_SIM_OBJ = bd_sim.o main_bd_sim.o
BD_SIM_DEP = bd_sim.d main_bd_sim.d

BD_FIT_SRC = bd_fit.cpp main_bd_fit.cpp
BD_FIT_OBJ = bd_fit.o main_bd_fit.o
BD_FIT_DEP = bd_fit.d main_bd_fit.d

NNI_SRC = main_nni.cpp
NNI_OBJ = main_nni.o
NNI_DEP = main_nni.d

UPGMA_SRC = upgma.cpp main_upgma.cpp
UPGMA_OBJ = upgma.o main_upgma.o
UPGMA_DEP = upgma.d main_upgma.d

2FA_SRC = main_s2fa.cpp
2FA_OBJ = main_s2fa.o
2FA_DEP = main_s2fa.d

2PHY_SRC = main_s2phy.cpp
2PHY_OBJ = main_s2phy.o
2PHY_DEP = main_s2phy.d

2NEX_SRC = main_s2nex.cpp
2NEX_OBJ = main_s2nex.o
2NEX_DEP = main_s2nex.d

FQFILT_SRC = main_fqfilt.cpp
FQFILT_OBJ = main_fqfilt.o
FQFILT_DEP = main_fqfilt.d

REVCOMP_SRC = main_revcomp.cpp edlib.cpp
REVCOMP_OBJ = main_revcomp.o edlib.o
REVCOMP_DEP = main_revcomp.d edlib.d

NW_SRC = main_nw.cpp
NW_OBJ = main_nw.o
NW_DEP = main_nw.d

SW_SRC = main_sw.cpp
SW_OBJ = main_sw.o
SW_DEP = main_sw.d

SEQSAMP_SRC = seq_sample.cpp main_boot.cpp
SEQSAMP_OBJ = seq_sample.o main_boot.o
SEQSAMP_DEP = seq_sample.d main_boot.d

SEQGEN_SRC = main_seqgen.cpp
SEQGEN_OBJ = main_seqgen.o
SEQGEN_DEP = main_seqgen.d

CONCAT_SRC = concat.cpp main_cat.cpp
CONCAT_OBJ = concat.o main_cat.o
CONCAT_DEP = concat.d main_cat.d

SSTAT_SRC = sstat.cpp main_sstat.cpp
SSTAT_OBJ = sstat.o main_sstat.o
SSTAT_DEP = sstat.d main_sstat.d

CONTRATES_SRC = main_contrates.cpp optimize_cont_models_nlopt.cpp
CONTRATES_OBJ = main_contrates.o optimize_cont_models_nlopt.o
CONTRATES_DEP = main_contrates.d optimize_cont_models_nlopt.d

SEQRECODE_SRC = recode.cpp main_recode.cpp
SEQRECODE_OBJ = recode.o main_recode.o
SEQRECODE_DEP = recode.d main_recode.d

BP_SRC = main_bp.cpp
BP_OBJ = main_bp.o
BP_DEP = main_bp.d

#BPSEQ_SRC = main_bpseq.cpp
#BPSEQ_OBJ = main_bpseq.o
#BPSEQ_DEP = main_bpseq.d

T2NEW_SRC = main_t2new.cpp
T2NEW_OBJ = main_t2new.o
T2NEW_DEP = main_t2new.d

T2NEX_SRC = main_t2nex.cpp
T2NEX_OBJ = main_t2nex.o
T2NEX_DEP = main_t2nex.d

RR_SRC = main_rr.cpp
RR_OBJ = main_rr.o
RR_DEP = main_rr.d

MONO_SRC = main_mono.cpp
MONO_OBJ = main_mono.o
MONO_DEP = main_mono.d

RMT_SRC = main_rmt.cpp
RMT_OBJ = main_rmt.o
RMT_DEP = main_rmt.d

TRT_SRC = main_trt.cpp
TRT_OBJ = main_trt.o
TRT_DEP = main_trt.d

RMK_SRC = main_rmk.cpp
RMK_OBJ = main_rmk.o
RMK_DEP = main_rmk.d

#removing for fortran, updating for non-fortran in process
#SM0_SRC = main_sm0.cpp
#SM0_OBJ = main_sm0.o
#SM0_DEP = main_sm0.d

#SM2A_SRC = main_sm2a.cpp
#SM2A_OBJ = main_sm2a.o
#SM2A_DEP = main_sm2a.d

CLSQ_SRC = clsq.cpp main_clsq.cpp
CLSQ_OBJ = clsq.o main_clsq.o
CLSQ_DEP = clsq.d main_clsq.d

CLTR_SRC = clean_tree.cpp main_cltr.cpp
CLTR_OBJ = clean_tree.o main_cltr.o
CLTR_DEP = clean_tree.d main_cltr.d

AA2C_SRC = aa2cdn.cpp main_aa2cdn.cpp
AA2C_OBJ = aa2cdn.o main_aa2cdn.o
AA2C_DEP = aa2cdn.d main_aa2cdn.d

TLATE_SRC = tlate.cpp main_tlate.cpp
TLATE_OBJ = tlate.o main_tlate.o
TLATE_DEP = tlate.d main_tlate.d

RMS_SRC = main_rms.cpp
RMS_OBJ = main_rms.o
RMS_DEP = main_rms.d

NJ_SRC = nj.cpp main_nj.cpp
NJ_OBJ = nj.o main_nj.o
NJ_DEP = nj.d main_nj.d

LOGMANIP_SRC = log_manip.cpp main_log.cpp
LOGMANIP_OBJ = log_manip.o main_log.o
LOGMANIP_DEP = log_manip.d main_log.d

VCF2FA_SRC = vcf_reader.cpp main_vcf2fa.cpp
VCF2FA_OBJ = vcf_reader.o main_vcf2fa.o
VCF2FA_DEP = vcf_reader.d main_vcf2fa.d

LS_SQ_SRC = seq_info.cpp main_lssq.cpp
LS_SQ_OBJ = seq_info.o main_lssq.o
LS_SQ_DEP = seq_info.d main_lssq.d

LS_TR_SRC = tree_info.cpp main_lstr.cpp
LS_TR_OBJ = tree_info.o main_lstr.o
LS_TR_DEP = tree_info.d main_lstr.d

COMPTEST_SRC = comp_test.cpp main_comp.cpp
COMPTEST_OBJ = comp_test.o main_comp.o
COMPTEST_DEP = comp_test.d main_comp.d

RELABEL_TREE_SRC = relabel.cpp main_rlt.cpp
RELABEL_TREE_OBJ = relabel.o main_rlt.o
RELABEL_TREE_DEP = relabel.d main_rlt.d

RELABEL_SEQ_SRC = relabel.cpp main_rls.cpp
RELABEL_SEQ_OBJ = relabel.o main_rls.o
RELABEL_SEQ_DEP = relabel.d main_rls.d

RESCALE_TREE_SRC = tscale.cpp main_tscale.cpp
RESCALE_TREE_OBJ = tscale.o main_tscale.o
RESCALE_TREE_DEP = tscale.d main_tscale.d

TCOL_SRC = main_tcol.cpp
TCOL_OBJ = main_tcol.o
TCOL_DEP = main_tcol.d

TCOMB_SRC = main_tcomb.cpp
TCOMB_OBJ = main_tcomb.o
TCOMB_DEP = main_tcomb.d

TGEN_SRC = tgen.cpp main_tgen.cpp
TGEN_OBJ = tgen.o main_tgen.o
TGEN_DEP = tgen.d main_tgen.d

SSORT_SRC = main_ssort.cpp
SSORT_OBJ = main_ssort.o
SSORT_DEP = main_ssort.d

COLLAPSE_TREE_SRC = collapse_tree.cpp main_colt.cpp
COLLAPSE_TREE_OBJ = collapse_tree.o main_colt.o
COLLAPSE_TREE_DEP = collapse_tree.d main_colt.d

CPP_SRCS += \
./utils.cpp \
./log.cpp \
./node.cpp \
./tree.cpp \
./tree_reader.cpp \
./tree_utils.cpp \
./sequence.cpp \
./seq_reader.cpp \
./seq_utils.cpp \
./seq_models.cpp \
./pairwise_alignment.cpp \
./superdouble.cpp \
./timer.cpp

RATE_SRCS += \
./rate_model.cpp \
./state_reconstructor.cpp \
./optimize_state_reconstructor_nlopt.cpp \
./optimize_state_reconstructor_periods_nlopt.cpp \
./branch_segment.cpp \
./cont_models.cpp \
./seq_gen.cpp 
#removing to get rid of fortran. update in process
#./mcmc.cpp \
#./state_reconstructor_simple.cpp \

CPP_OBJS += \
./utils.o \
./log.o \
./node.o \
./tree.o \
./tree_reader.o \
./tree_utils.o \
./sequence.o \
./seq_reader.o \
./seq_utils.o \
./seq_models.o \
./pairwise_alignment.o \
./superdouble.o \
./timer.o

RATE_OBJS += \
./rate_model.o \
./state_reconstructor.o \
./optimize_state_reconstructor_nlopt.o \
./optimize_state_reconstructor_periods_nlopt.o \
./branch_segment.o \
./cont_models.o \
./seq_gen.o
#removing to get rid of fortran. update in process
#./mcmc.o \
#./state_reconstructor_simple.o \

CPP_DEPS += \
./utils.d \
./log.d \
./node.d \
./tree.d \
./tree_reader.d \
./tree_utils.d \
./sequence.d \
./seq_reader.d \
./seq_utils.d \
./seq_models.d \
./pairwise_alignment.d \
./superdouble.d \
./timer.d

RATE_DEPS += \
./rate_model.d \
./state_reconstructor.d \
./optimize_state_reconstructor_nlopt.d \
./optimize_state_reconstructor_periods_nlopt.d \
./branch_segment.d \
./cont_models.d \
./seq_gen.d
#removing to get rid of fortran. update in process
#./mcmc.d \
#./state_reconstructor_simple.d \


# Each subdirectory must supply rules for building sources it contributes
%.o: ./%.cpp
	$(CXX) $(OPT_FLAGS) $(CPPFLAGS) $(LDFLAGS) -c -fmessage-length=0 -MMD -MP -MF "$(@:%.o=%.d)" -o "$@" "$<"

PROGS := pxmrca pxmrcacut pxmrcaname pxconsq pxbdsim pxlstr pxlssq pxupgma pxclsq pxcltr pxs2fa pxs2phy pxs2nex pxfqfilt pxrevcomp pxnw pxsw pxboot pxcat pxsstat pxrecode pxbp pxt2new pxt2nex pxrr pxmono pxaa2cdn pxtlate pxrms pxrmt pxtrt pxrmk pxnj pxlog pxvcf2fa pxrlt pxrls pxtscale pxstrec pxseqgen pxssort pxcontrates pxtcol pxtcomb pxtgen pxssort pxcolt pxcomp $(NLOPT_PROGRAMS)

# default all target
all: $(PROGS)

pxstrec: $(CPP_OBJS) $(RATE_OBJS) $(STREC_OBJ) #$(FORT_OBJS)
	@echo 'building pxstrec'
	$(CXX) -o "pxstrec" $(OPT_FLAGS) $(STREC_OBJ) $(CPP_OBJS) $(RATE_OBJS) $(CPPFLAGS) $(LDFLAGS) $(CPP_LIBS) #$(FORT_OBJS) -lgfortran
	cat man/$@.1.in > man/$@.1

pxmrca: $(CPP_OBJS) $(MRCA_OBJ)
	@echo 'building pxmrca'
	$(CXX) -o "pxmrca" $(OPT_FLAGS) $(MRCA_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxmrcacut: $(CPP_OBJS) $(MRCACUT_OBJ)
	@echo 'building pxmrcacut'
	$(CXX) -o "pxmrcacut" $(OPT_FLAGS) $(MRCACUT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxmrcaname: $(CPP_OBJS) $(MRCANAME_OBJ)
	@echo 'building pxmrcaname'
	$(CXX) -o "pxmrcaname" $(OPT_FLAGS) $(MRCANAME_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxconsq: $(CPP_OBJS) $(CONSEQ_OBJ)
	@echo 'building pxconsq'
	$(CXX) -o "pxconsq" $(OPT_FLAGS) $(CONSEQ_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxbdsim: $(CPP_OBJS) $(BD_SIM_OBJ)
	@echo 'building pxbdsim'
	$(CXX) -o "pxbdsim" $(OPT_FLAGS) $(BD_SIM_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxbdfit: $(CPP_OBJS) $(BD_FIT_OBJ)
	@echo 'building pxbdfit'
	$(CXX) -o "pxbdfit" $(OPT_FLAGS) $(BD_FIT_OBJ) $(CPP_OBJS) $(CPPFLAGS) $(LDFLAGS) $(CPP_LIBS)
	cat man/$@.1.in > man/$@.1

pxnni: $(CPP_OBJS) $(NNI_OBJ)
	@echo 'building pxnni'
	$(CXX) -o "pxnni" $(OPT_FLAGS) $(NNI_OBJ) $(CPP_OBJS) $(CPPFLAGS) $(LDFLAGS) $(CPP_LIBS)
	cat man/$@.1.in > man/$@.1

pxlstr: $(CPP_OBJS) $(LS_TR_OBJ)
	@echo 'building pxlstr'
	$(CXX) -o "pxlstr" $(OPT_FLAGS) $(LS_TR_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxlssq: $(CPP_OBJS) $(LS_SQ_OBJ)
	@echo 'bulding pxlssq'
	$(CXX) -o "pxlssq" $(OPT_FLAGS) $(LS_SQ_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxupgma: $(CPP_OBJS) $(UPGMA_OBJ)
	@echo 'building pxupgma'
	$(CXX) -o "pxupgma" $(OPT_FLAGS) $(UPGMA_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxnj: $(CPP_OBJS) $(NJ_OBJ)
	@echo 'building pxnj'
	$(CXX) -o "pxnj" $(OPT_FLAGS) $(NJ_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxclsq: $(CPP_OBJS) $(CLSQ_OBJ)
	@echo 'building pxclsq'
	$(CXX) -o "pxclsq" $(OPT_FLAGS) $(CLSQ_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxcltr: $(CPP_OBJS) $(CLTR_OBJ)
	@echo 'building pxcltr'
	$(CXX) -o "pxcltr" $(OPT_FLAGS) $(CLTR_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrms: $(CPP_OBJS) $(RMS_OBJ)
	@echo 'building pxrms'
	$(CXX) -o "pxrms" $(OPT_FLAGS) $(RMS_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxtlate: $(CPP_OBJS) $(TLATE_OBJ)
	@echo 'building pxtlate'
	$(CXX) -o "pxtlate" $(OPT_FLAGS) $(TLATE_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxaa2cdn: $(CPP_OBJS) $(AA2C_OBJ)
	@echo 'building pxaa2cdn'
	$(CXX) -o "pxaa2cdn" $(OPT_FLAGS) $(AA2C_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxs2fa: $(CPP_OBJS) $(2FA_OBJ)
	@echo 'building pxs2fa'
	$(CXX) -o "pxs2fa" $(OPT_FLAGS) $(2FA_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxs2phy: $(CPP_OBJS) $(2PHY_OBJ)
	@echo 'building pxs2phy'
	$(CXX) -o "pxs2phy" $(OPT_FLAGS) $(2PHY_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxs2nex: $(CPP_OBJS) $(2NEX_OBJ)
	@echo 'building pxs2nex'
	$(CXX) -o "pxs2nex" $(OPT_FLAGS) $(2NEX_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxfqfilt: $(CPP_OBJS) $(FQFILT_OBJ)
	@echo 'building pxfqfilt'
	$(CXX) -o "pxfqfilt" $(OPT_FLAGS) $(FQFILT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrevcomp: $(CPP_OBJS) $(REVCOMP_OBJ)
	@echo 'building pxrevcomp'
	$(CXX) -o "pxrevcomp" $(OPT_FLAGS) $(REVCOMP_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxnw: $(CPP_OBJS) $(NW_OBJ)
	@echo 'building pxnw'
	$(CXX) -o "pxnw" $(OPT_FLAGS) $(NW_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxsw: $(CPP_OBJS) $(SW_OBJ)
	@echo 'building pxsw'
	$(CXX) -o "pxsw" $(OPT_FLAGS) $(SW_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxboot: $(CPP_OBJS) $(SEQSAMP_OBJ)
	@echo 'building pxboot'
	$(CXX) -o "pxboot" $(OPT_FLAGS) $(SEQSAMP_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxseqgen: $(CPP_OBJS) $(RATE_OBJS) $(SEQGEN_OBJ) $(FORT_OBJS)
	@echo 'building pxseqgen'
	$(CXX) -o "pxseqgen" $(OPT_FLAGS) $(SEQGEN_OBJ) $(CPP_OBJS) $(RATE_OBJS) $(CPPFLAGS) $(LDFLAGS) $(CPP_LIBS)
	cat man/$@.1.in > man/$@.1

pxcat: $(CPP_OBJS) $(CONCAT_OBJ)
	@echo 'building pxcat'
	$(CXX) -o "pxcat" $(OPT_FLAGS) $(CONCAT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxsstat: $(CPP_OBJS) $(SSTAT_OBJ)
	@echo 'building pxsstat'
	$(CXX) -o "pxsstat" $(OPT_FLAGS) $(SSTAT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxlog: $(CPP_OBJS) $(LOGMANIP_OBJ)
	@echo 'building pxlog'
	$(CXX) -o "pxlog" $(OPT_FLAGS) $(LOGMANIP_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxvcf2fa: $(CPP_OBJS) $(VCF2FA_OBJ)
	@echo 'building pxvcf2fa'
	$(CXX) -o "pxvcf2fa" $(OPT_FLAGS) $(VCF2FA_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxcontrates: $(CPP_OBJS) $(CONTRATES_OBJ) $(RATE_OBJS)
	@echo 'building pxcontrates'
	$(CXX) -o "pxcontrates" $(OPT_FLAGS) $(CONTRATES_OBJ) $(RATE_OBJS) $(CPP_OBJS) $(CPPFLAGS) $(LDFLAGS) $(CPP_LIBS)
	cat man/$@.1.in > man/$@.1

pxrecode: $(CPP_OBJS) $(SEQRECODE_OBJ)
	@echo 'building pxrecode'
	$(CXX) -o "pxrecode" $(OPT_FLAGS) $(SEQRECODE_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxbp: $(CPP_OBJS) $(BP_OBJ)
	@echo 'building pxbp'
	$(CXX) -o "pxbp" $(OPT_FLAGS) $(BP_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxt2new: $(CPP_OBJS) $(T2NEW_OBJ)
	@echo 'building pxt2new'
	$(CXX) -o "pxt2new" $(OPT_FLAGS) $(T2NEW_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxt2nex: $(CPP_OBJS) $(T2NEX_OBJ)
	@echo 'building pxt2nex'
	$(CXX) -o "pxt2nex" $(OPT_FLAGS) $(T2NEX_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1
	
pxrr: $(CPP_OBJS) $(RR_OBJ)
	@echo 'building pxrr'
	$(CXX) -o "pxrr" $(OPT_FLAGS) $(RR_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxmono: $(CPP_OBJS) $(MONO_OBJ)
	@echo 'building pxmono'
	$(CXX) -o "pxmono" $(OPT_FLAGS) $(MONO_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrmt: $(CPP_OBJS) $(RMT_OBJ)
	@echo 'building pxrmt'
	$(CXX) -o "pxrmt" $(OPT_FLAGS) $(RMT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxtrt: $(CPP_OBJS) $(TRT_OBJ)
	@echo 'building pxtrt'
	$(CXX) -o "pxtrt" $(OPT_FLAGS) $(TRT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrmk: $(CPP_OBJS) $(RMK_OBJ)
	@echo 'building pxrmk'
	$(CXX) -o "pxrmk" $(OPT_FLAGS) $(RMK_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

#removing until fortran update
#pxsm0: $(CPP_OBJS) $(RATE_OBJS) $(SM0_OBJ) $(FORT_OBJS)
#	@echo 'building pxsm0'
#	$(CXX) -o "pxsm0" $(OPT_FLAGS) $(SM0_OBJ) $(CPP_OBJS) $(RATE_OBJS) $(FORT_OBJS) $(CPP_LIBS) -lgfortran

#pxsm2a: $(CPP_OBJS) $(RATE_OBJS) $(SM2A_OBJ) $(FORT_OBJS)
#	@echo 'building pxsm2a'
#	$(CXX) -o "pxsm2a" $(OPT_FLAGS) $(SM2A_OBJ) $(CPP_OBJS) $(RATE_OBJS) $(FORT_OBJS) $(CPP_LIBS) -lgfortran

pxcomp: $(CPP_OBJS) $(COMPTEST_OBJ)
	@echo 'building pxcomp'
	$(CXX) -o "pxcomp" $(OPT_FLAGS) $(COMPTEST_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrlt: $(CPP_OBJS) $(RELABEL_TREE_OBJ)
	@echo 'building pxrlt'
	$(CXX) -o "pxrlt" $(OPT_FLAGS) $(RELABEL_TREE_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxrls: $(CPP_OBJS) $(RELABEL_SEQ_OBJ)
	@echo 'building pxrls'
	$(CXX) -o "pxrls" $(OPT_FLAGS) $(RELABEL_SEQ_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxtscale: $(CPP_OBJS) $(RESCALE_TREE_OBJ)
	@echo 'building pxtscale'
	$(CXX) -o "pxtscale" $(OPT_FLAGS) $(RESCALE_TREE_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1
	
pxtcol: $(CPP_OBJS) $(TCOL_OBJ)
	@echo 'building pxtcol'
	$(CXX) -o "pxtcol" $(OPT_FLAGS) $(TCOL_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxtcomb: $(CPP_OBJS) $(TCOMB_OBJ)
	@echo 'building pxtcomb'
	$(CXX) -o "pxtcomb" $(OPT_FLAGS) $(TCOMB_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxtgen: $(CPP_OBJS) $(TGEN_OBJ)
	@echo 'building pxtgen'
	$(CXX) -o "pxtgen" $(OPT_FLAGS) $(TGEN_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxssort: $(CPP_OBJS) $(SSORT_OBJ)
	@echo 'building pxssort'
	$(CXX) -o "pxssort" $(OPT_FLAGS) $(SSORT_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

pxcolt: $(CPP_OBJS) $(COLLAPSE_TREE_OBJ)
	@echo 'building pxcolt'
	$(CXX) -o "pxcolt" $(OPT_FLAGS) $(COLLAPSE_TREE_OBJ) $(CPP_OBJS)
	cat man/$@.1.in > man/$@.1

install:
	mkdir -p $(PREFIX)/bin && install -m 0755 px* $(PREFIX)/bin
	mkdir -p $(MANDIR)/man1 && install -m 0755 man/px*.1 $(MANDIR)/man1

uninstall:
	-$(RM) $(addprefix $(PREFIX)/bin/, $(PROGS))
	-$(RM) $(addprefix $(MANDIR)/man1/, $(addsuffix .1, $(PROGS)))

# Other Targets
clean:
	-$(RM) *.o *.d px* man/px*.1

distclean:
	-$(RM) *.o *.d px* man/px*.1 configure config.log config.h config.status Makefile

check:
	python3 run_tests.py

test:
	python3 run_tests.py
